import { NIcon } from "naive-ui";
import { Component, h } from "vue";
import { useThemeConfig } from "../bean/GlobalConfig";
// @ts-ignore
import { CRUD_ColumnsOption, CRUD_ItemInfo } from "/@/bean/GlobalEntity";
import HzEchartsPieSimple from "/@com/echarts/pie/Hz-Echarts-Pie-Simple.vue";
import HzEchartsPieHalfDonut from "/@com/echarts/pie/Hz-Echarts-Pie-Half-Donut.vue";
import HzEchartsPieDoughnut from "/@com/echarts/pie/Hz-Echarts-Pie-Doughnut.vue";
import HzEchartsPieBorderRadius from "/@com/echarts/pie/Hz-Echarts-Pie-BorderRadius.vue";
import HzEchartsBarNegative from "/@com/echarts/bar/Hz-Echarts-Bar-Negative.vue";
import HzEchartsBarRace from "/@com/echarts/bar/Hz-Echarts-Bar-Race.vue";
import HzEchartsBarSimple from "/@com/echarts/bar/Hz-Echarts-Bar-Simple.vue";
import HzEchartsBarTangential from "/@com/echarts/bar/Hz-Echarts-Bar-Tangential.vue";
import HzEchartsKLineSimple from "/@com/echarts/kline/Hz-Echarts-KLine-Simple.vue";
import HzEchartsKLineSZ from "/@com/echarts/kline/Hz-Echarts-KLine-SZ.vue";
import HzEchartsLineArea from "/@com/echarts/line/Hz-Echarts-Line-Area.vue";
import HzEchartsLineAreaStacked from "/@com/echarts/line/Hz-Echarts-Line-AreaStacked.vue";
import HzEchartsLineSimple from "/@com/echarts/line/Hz-Echarts-Line-Simple.vue";
import HzEchartsLineSmooth from "/@com/echarts/line/Hz-Echarts-Line-Smooth.vue";
import HzEchartsLineStacked from "/@com/echarts/line/Hz-Echarts-Line-Stacked.vue";
import HzMapGaode from "/@com/echarts/map/Hz-Map-Gaode.vue";
import HzEchartsWordCloud from "/@com/echarts/wordcloud/Hz-Echarts-WordCloud.vue";
import HzChinaMap from "/@com/echarts/map/Hz-China-Map.vue";
import HzEchartsBarBackGround from "/@com/echarts/bar/Hz-Echarts-Bar-BackGround.vue";
import HzEchartsWordCloud2 from "/@com/echarts/wordcloud/Hz-Echarts-WordCloud-2.vue";
import HzItemDescribeCard from "/@com/item-desc/Hz-Item-DescribeCard.vue";
import HzEchartsRadarSimple from "/@com/echarts/radar/Hz-Echarts-Radar-Simple.vue";
import HzBox7 from "/@com/hz-box/Hz-Box-7.vue";
import HzBox1 from "/@com/hz-box/Hz-Box-1.vue";
import HzBox2 from "/@com/hz-box/Hz-Box-2.vue";
import HzBox3 from "/@com/hz-box/Hz-Box-3.vue";
import HzBox4 from "/@com/hz-box/Hz-Box-4.vue";
import HzBox5 from "/@com/hz-box/Hz-Box-5.vue";
import HzBox6 from "/@com/hz-box/Hz-Box-6.vue";
import HzBox8 from "/@com/hz-box/Hz-Box-8.vue";
import HzBox9 from "/@com/hz-box/Hz-Box-9.vue";
import HzBox10 from "/@com/hz-box/Hz-Box-10.vue";
import HzEchartsBarDataSet from "/@com/echarts/bar/Hz-Echarts-Bar-DataSet.vue";
import HzEchartsScatterSimple from "/@com/echarts/scatter/Hz-Echarts-Scatter-Simple.vue";
import HzEchartsScatterLinearRegression from "/@com/echarts/scatter/Hz-Echarts-Scatter-Linear-Regression.vue";
import HzEchartsScatterCluster from "/@com/echarts/scatter/Hz-Echarts-Scatter-Cluster.vue";
import HzEchartsDashboard1 from "/@com/echarts/dashboard/Hz-Echarts-Dashboard-1.vue";
import HzTableScroll from "/@com/table/Hz-Table-Scroll.vue";
import HzTop1 from "/@com/hz-top/Hz-Top-1.vue";
import HzTop2 from "/@com/hz-top/Hz-Top-2.vue";
import HzTop3 from "/@com/hz-top/Hz-Top-3.vue";
import HzTop4 from "/@com/hz-top/Hz-Top-4.vue";
import HzTop5 from "/@com/hz-top/Hz-Top-5.vue";
import HzTop6 from "/@com/hz-top/Hz-Top-6.vue";
import HzEmpty from "/@com/occupy/Hz-Empty.vue";
import HZAirQualityMap from "/@com/echarts/map/HZ-Air-Quality-Map.vue";
import HZForecast01 from "/@com/forecast/HZ-Forecast01.vue";
import HZForecast02 from "/@com/forecast/HZ-Forecast02.vue";
import HZForecast03 from "/@com/forecast/HZ-Forecast03.vue";
import HZForecast04 from "/@com/forecast/HZ-Forecast04.vue";
import HZForecast05 from "/@com/forecast/HZ-Forecast05.vue";
import HZForecast06 from "/@com/forecast/HZ-Forecast06.vue";
import HZForecast07 from "/@com/forecast/HZ-Forecast07.vue";
import HZForecast08 from "/@com/forecast/HZ-Forecast08.vue";
export function renderIcon(icon: Component) {
    return () => h(NIcon, null, { default: () => h(icon) })
}

const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig);

const getThemeConfig = computed(() => {
    return themeConfig.value;
});

export function getEchartsTheme(): string | null {
    if (getThemeConfig.value.theme) {
        return 'dark';
    } else {
        return null;
    }
}

export function getEchartsTextColor(): any {
    return getThemeConfig.value.theme ? "rgb(255,255,255)" : "rgb(0,0,0)"
}

// 根据CRUD_ItemInfo数组生成CRUD_ColumnsOption
export function grenateColumnsOption(itemInfo: CRUD_ItemInfo[]): CRUD_ColumnsOption[] {
    let columnsOption: CRUD_ColumnsOption[] = []
    itemInfo.forEach((item: CRUD_ItemInfo) => {
        columnsOption.push({
            title: item.label,
            key: item.key,
            width: 100,
            ellipsis: { tooltip: true },
            disabled: item.disabled,
        })
    })
    return columnsOption
}

// 根据CRUD_ItemInfo数组生成From表单(以key为name,value为'')
export function grenateForm(itemInfo: CRUD_ItemInfo[]): any {
    let form: any = {}
    itemInfo.forEach((item: CRUD_ItemInfo) => {
        form[item.key] = ''
    })
    return form
}

// 保存文件到本地
export const saveFile = (content: any, fileName: any, fileType: any) => {
    const a = document.createElement('a')
    const file = new Blob([content], { type: fileType })
    a.href = URL.createObjectURL(file)
    a.download = fileName
    a.click()
    URL.revokeObjectURL(a.href)
}

// 根据name获取组件
export const getHzCom = (name: string): Component | null => {
    switch (name) {
        case 'HzEchartsPieSimple':
            return HzEchartsPieSimple;
        case 'HzEchartsPieHalfDonut':
            return HzEchartsPieHalfDonut;
        case 'HzEchartsPieDoughnut':
            return HzEchartsPieDoughnut;
        case 'HzEchartsPieBorderRadius':
            return HzEchartsPieBorderRadius;
        case 'HzEchartsBarNegative':
            return HzEchartsBarNegative;
        case 'HzEchartsBarRace':
            return HzEchartsBarRace;
        case 'HzEchartsBarSimple':
            return HzEchartsBarSimple;
        case 'HzEchartsBarTangential':
            return HzEchartsBarTangential;
        case 'HZEchartsKLineSimple':
            return HzEchartsKLineSimple;
        case 'HZEchartsKLineSZ':
            return HzEchartsKLineSZ;
        case 'HZEchartsLineArea':
            return HzEchartsLineArea;
        case 'HZEchartsLineAreaStacked':
            return HzEchartsLineAreaStacked;
        case 'HZEchartsLineSimple':
            return HzEchartsLineSimple;
        case 'HZEchartsLineSmooth':
            return HzEchartsLineSmooth;
        case 'HZEchartsLineStacked':
            return HzEchartsLineStacked;
        case 'HzMapGaode':
            return HzMapGaode;
        case 'HzEchartsWordCloud':
            return HzEchartsWordCloud;
        case 'HzChinaMap':
            return HzChinaMap;
        case 'HzEchartsBarBackGround':
            return HzEchartsBarBackGround;
        case 'HzEchartsWordCloud2':
            return HzEchartsWordCloud2;
        case 'HzItemDescribeCard':
            return HzItemDescribeCard;
        case 'HzEchartsRadarSimple':
            return HzEchartsRadarSimple;
        case 'HzBox7':
            return HzBox7;
        case 'HzBox1':
            return HzBox1;
        case 'HzBox2':
            return HzBox2;
        case 'HzBox3':
            return HzBox3;
        case 'HzBox4':
            return HzBox4;
        case 'HzBox5':
            return HzBox5;
        case 'HzBox6':
            return HzBox6;
        case 'HzBox8':
            return HzBox8;
        case 'HzBox9':
            return HzBox9;
        case 'HzBox10':
            return HzBox10;
        case 'HzEchartsBarDataSet':
            return HzEchartsBarDataSet;
        case 'HzEchartsScatterSimple':
            return HzEchartsScatterSimple;
        case 'HzEchartsScatterLinearRegression':
            return HzEchartsScatterLinearRegression;
        case 'HzEchartsScatterCluster':
            return HzEchartsScatterCluster;
        case 'HzEchartsDashboard1':
            return HzEchartsDashboard1;
        case 'HzTableScroll':
            return HzTableScroll;
        case 'HzTop1':
            return HzTop1;
        case 'HzTop2':
            return HzTop2;
        case 'HzTop3':
            return HzTop3;
        case 'HzTop4':
            return HzTop4;
        case 'HzTop5':
            return HzTop5;
        case 'HzTop6':
            return HzTop6;
        case 'HzEmpty':
            return HzEmpty;
        case 'HZAirQualityMap':
            return HZAirQualityMap;
        case 'HZForecast01':
            return HZForecast01;
        case 'HZForecast02':
            return HZForecast02;
        case 'HZForecast03':
            return HZForecast03;
        case 'HZForecast04':
            return HZForecast04;
        case 'HZForecast05':
            return HZForecast05;
        case 'HZForecast06':
            return HZForecast06;
        case 'HZForecast07':
            return HZForecast07;
        case 'HZForecast08':
            return HZForecast08;
        default:
            return null;
    }
}
